//获取token
export const getToken = () => {
	try {
		const value = uni.getStorageSync('token');
		if (value) {
			return value
		}
		return
	} catch (e) {
		return
		// error
	}
}

//获取当前路径
export const getCurrentPath = () => {
	let pages = getCurrentPages();
	let currentPath = ''
	if (!pages.length) {
		currentPath = '/' + 'pages/tabBar/home/index'
	} else {
		currentPath = pages[pages.length - 1].$page.fullPath; //完整路由地址
	}
	return currentPath
}

export const isBound = () => {
	const value = uni.getStorageSync('bound');
	if (!value) {
		const currentPath = getCurrentPath()
		uni.navigateTo({
			url: `/pages/bind-mobile/index?backUrl=${encodeURIComponent(currentPath)}`
		});
		return
	}
	return value
}

// 是否登录
export const isGoLogin = () => {

	const token = getToken()
	const currentPath = getCurrentPath()
	if (!token) {
		uni.reLaunch({
			url: `/pages/login/index?backUrl=${encodeURIComponent(currentPath)}`
		});
		return false
	}
	return isBound()
}

export const getUrlOption = () => {
	const path = getCurrentPath()
	let [url, seearch] = path.split('?')
	let str = seearch ? seearch.split("&") : [];
	let obj = {};
	str.forEach(e => {
		let list = e.split("=");
		obj[list[0]] = list[1];
	});
	return obj
}


export const getHello = () => {
	const date = new Date();
	const hour = date.getHours();
	if (hour >= 0 && hour < 12) {
		return "上午好";
	} else if (hour === 12) {
		return "中午好";
	} else if (hour > 12 && hour < 18) {
		return "下午好";
	} else {
		return "晚上好";
	}
}
